<?php 
	require_once("models/config.php");
	require_once("pie.php");

	require_once("graphs/graph-settings.php");
	
	if (!isUserViewAuthorized()) {
		echo "Unauthorized access";
		die();
	}
	
	$usedUser = $_GET['userId'];
	
	global $loggedInUser;
	global $db;

	$sql = "SELECT `detection_Ways`.`Name` AS Name, COUNT(*) AS Count 
			FROM `debugging_Reports` JOIN `detection_Ways` ON `debugging_Reports`.`Detection_Way` = `detection_Ways`.`Id` JOIN `detection_Way_Subcategories` ON `detection_Ways`.`SubcategoryId` = `detection_Way_Subcategories`.`Id`
			WHERE (((`Review_Reason` IS NULL) OR (`Reviewed` = 1)) AND `debugging_Reports`.`User` = $usedUser)
			GROUP BY `detection_Ways`.`Id`";
	
	$result = $db->sql_query($sql);
	if (!$result) {
		$error = $db->sql_error();
		return;
	}
		
	$data = array();
	$names = array();
	$rows = $db->sql_fetchall();
	foreach($rows as $i => $row) {
		$data[] = $row['Count'];
		$names[] = $row['Name'];
	}

	drawPie($data, $names,
		GRAPH_WIDTH,
		GRAPH_HEIGHT,
		DEFAULT_PIE_RADIUS,
		DEFAULT_LABEL_LEFT,
		DEFAULT_PIE_TOP,
		DEFAULT_TITLE_BAR_HEIGHT,
		"Count of detections");
	?>
